package com.bonc.modules.common.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonc.modules.common.dao.StdCodeDao;
import com.bonc.modules.common.entity.StdCode;
import com.bonc.modules.common.service.StdCodeService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author jinlong
 * @date 2021/7/27
 */
@Service
public class StdCodeServiceImpl extends ServiceImpl<StdCodeDao, StdCode> implements StdCodeService {
    @Override
    public Map<String, StdCode> getConfMap(String stdType) {
        LambdaQueryWrapper<StdCode> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(stdType)) {
            queryWrapper.eq(StdCode::getStdType, stdType);
        }
        queryWrapper.orderByAsc(StdCode::getStdCode);
        List<StdCode> stdCodeList = this.baseMapper.selectList(queryWrapper);
        return stdCodeList.stream().collect(Collectors.toMap(StdCode::getStdCode, stdCode -> stdCode));
    }
}
